<%@page import="com.kh.pajx.sop.util.common.FormatDate"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<%
	String path = request.getContextPath();
	String temp_str = FormatDate.getUseDate(new Date());
%>
<script language="javascript" type="text/javascript" src="${pageContext.request.contextPath}/script/js/jquery.PrintArea.js"></script>
<script type="text/javascript">
function showTr(sid,state){
	var tr ="";
	var whichEl = document.getElementById("tr" + sid);
	var datalist=$("#foreign"+sid);
	datalist.empty();
	if (whichEl.style.display == "none") {
		if(state==1){
			var data={"foreign.appBillCode":sid};
			var url="foreign_findForeignList.action";
	$.post(url,data,function(message){
		var list=message;
		var str=list.split(";");
		for ( var i = 0; i < str.length-1; i++) {
			tr+="<tr>";
			var str1=str[i].split(",");
			for ( var j = 2; j< str1.length-1; j++) {
				if(j==10||j==12||j==14||j==16){
					tr+="<td><span style='color:red'>"
						 +str1[j]
						  +"</span></td>";
				}else if(j==2){
					   tr+="<td><a href='javascript:void(0)' onclick='alertDiv("
						    +1+","+"\""+str1[18]+"\""
							+")'>"
							 +str1[2]
							 +"</a></td>"; 
				}else{
				   tr+="<td>"
				   +str1[j]
				    +"</span></td>";
			  }
			}
			tr+="</tr>";
		}
		   datalist.append(tr);
		   whichEl.style.display = "";
		   initRemoveAllNode(sid);
	      })
		}else{
			var data={"areaManger.appBillCode":sid};
			var url="foreign_findAreaMangerList.action";
			$.post(url,data,function(message){
				var list=message;
				var str=list.split(";");
				for ( var i = 0; i < str.length-1; i++) {
					tr+="<tr>";
					var str1=str[i].split(",");
					for ( var j = 2; j< str1.length-1; j++) {
						if(j==11){
							tr+="<td><span style='color:red'>"
								 +str1[j]
								  +"</span></td>";
						}else if(j==2){
							   tr+="<td><a href='javascript:void(0)' onclick='alertDiv("
								    +2+","+"\""+str1[13]+"\""
								    +")'>"
									 +str1[2]
									 +"</a></td>"; 
						}else{
						tr+="<td>"
						 +str1[j]
						  +"</span></td>";
					  }
					}
					tr+="</tr>";
				}
				datalist.append(tr);
				whichEl.style.display = "";
				initRemoveAllNode(sid);
			})
		}
	}else{
		 initRemoveNode(sid);
	}
}
function  initRemoveNode(sid){
	var whichEl = document.getElementById("tr" + sid);
	whichEl.style.display = "none";
}
function  initRemoveAllNode(sid){
	　var whichEl=document.getElementsByName("tr_code");
			for(var i=0;i<whichEl.length;i++){
				if(whichEl[i].value!=sid){
					var tr= document.getElementById("tr" + whichEl[i].value);
					if(tr.style.display = "none"){
					}else{
				   tr.style.display = "none";
				     $("#tr" + whichEl[i].value).empty();
					}
				}
			}
	 };
	 function deleteForeign() {
		 var deleteTrApp=$("#tablemanage tr.selected").attr('deleteTrApp');
		 console.log(deleteTrApp);
		 if(typeof(deleteTrApp) != "undefined"){
				var id=deleteTrApp.split(",")[0];
				var code=deleteTrApp.split(",")[1];
		 alertMsg.confirm("确定要撤销吗？", {
				okCall : function() {
			var data = {
					"model.uuid":id,
					"foreign.appBillCode":code,
					"billState":1
			};
			var url = "foreign_updateBalanceApp.action";
			 $.ajax({ 
				  url: url, 
				  type:"post",
				  data :data,
				  dataType:"json",
				  success: function(message){
					  navTabAjaxDone(message);
			      }});
				}})
		 }else{
				alertMsg.info("请选择一条记录");
			}
		};
		  function alertDiv(str1,str2){
				 if(str1==""||str2==""){
					 alertMsg.error("数据异常");
					 return;
				 }
				 $.pdialog.open("foreign_oldOrderList.action?orderType="+str1+"&orderUuid="+encodeURIComponent(str2),"oldList2","单据列表","{width:968px,height:400px,max:true,mask:true,fresh:true}");
			  }
</script>
<div class="pageHeader">
	<form id="pagerForm" method="post" action="foreign_appManageList.action">
	<input type="hidden" name="pageNum" value="${currentPage}" />
	<input type="hidden" name="numPerPage" value="${numPerPage}" />
	<input type="hidden" value="${saleId}" name="saleId">
	</form>
				<form onsubmit="return navTabSearch(this);" action="foreign_appManageList.action" method="post" >
			<div class="searchBar nowrap">
			<p><label>部&nbsp;&nbsp;门：</label><select name="deptCode" id="deptCode" class="combox" ref="ManageId"
														refUrl="school_getAllSaler.action?deptCode={value}">
									<option value="">---所有部门---</option>
									<c:forEach items="${deptList}" var="dept">
										<option ${deptCode==dept.deptCode?"selected":""} value="${dept.deptCode}">${dept.deptName}</option>
									</c:forEach>
							</select>
				</p>
				<p><label>销售人员</label>
							<select name="saleId" id="ManageId"
								class="required combox">
									<option value="">---请选择---</option>
							</select>
				</p>
			<div class="subBar" float="left">
				<ul>
					<li>
					<div class="buttonActive" ><div class="buttonContent"><button type="submit">检索</button></div></div>
					</li>
				</ul>
			</div>
		</div>
		</form></div>
<div class="pageContent">
	<div class="panelBar">
		<ul class="toolBar">
			<li><a class="add" href="javascript:void(0)" onclick="deleteForeign()"><span>撤销</span></a></li>
			<li class="line">line</li>
			
		</ul>             
	</div>
		<div >
			<table class="list" width="100%" layoutH="90" id="tablemanage">
				<thead>
					<tr>
						<th>申请单号</th>
						<th>申请类型</th>
						<th>申请人</th>
						<th>申请金额</th>
						<th>申请日期</th>
						<th>审批人</th>
						<th>审批日期</th>
						<th>审批金额</th>
						<th>签批人</th>
						<th>签批日期</th>
					</tr>
				</thead>

				<tbody>
					<c:forEach items="${recordList}" var="fb" varStatus="countStatus">
						<tr id="row${fb.uuid}" deleteTrApp="${fb.uuid},${fb.appBillCode}" >
							<td ><a href="javascript:void(0);" onclick="showTr('${fb.appBillCode}','${fb.appType}')">${fb.appBillCode}</a></td>
							<td>
							<c:if test="${fb.appType==1}">对外结算</c:if>
							<c:if test="${fb.appType==2}">行业经理</c:if>
							</td>
							<td>
								<script>
								 var url="foreign_findUser.action?timestamp="+ new Date().getTime();
								 var data={saleId:'${fb.appPerson}'};
									$.post(url,data,function(message){
										var msg=message;
										$("#appManageList_appperson_"+${countStatus.count}).text(msg);
									})
								 </script>
								 <span id="appManageList_appperson_${countStatus.count}"></span>
							</td>
							<td>${fb.appSumFee}</td>
						<td>
						<f:parseDate value="${fb.appDate}"
									pattern="yyyyMMddHHmm" var="test" /> <f:formatDate
									value="${test}" pattern="yyyy-MM-dd HH:mm"  />
						<f:parseDate value="${fb.appDate}"
									pattern="yyyyMMddHHmm" var="test" /> <f:formatDate
									value="${test}" pattern="yyyy-MM-dd HH:mm"  var ="appDate"/>
						</td>
						<td>
							<c:if test="${!empty fb.chkPerson}">
							<script>
							 var url="foreign_findUser.action?timestamp="+ new Date().getTime();
							 var data={saleId:'${fb.chkPerson}'};
								$.post(url,data,function(message){
									var msg=message;
									$("#appManageList_checkperson_"+${countStatus.count}).text(msg);
								})
							 </script>
							 <span id="appManageList_checkperson_${countStatus.count}"></span>
							 </c:if>
						</td>
						<td><f:parseDate value="${fb.chkDate}"
									pattern="yyyyMMddHHmm" var="test" /> <f:formatDate
									value="${test}" pattern="yyyy-MM-dd HH:mm" />
						</td>
						<td>
						${fb.chkMoney}
						</td>
						<td>
						</td>
						<td><f:parseDate value="${fb.payDate}"
									pattern="yyyyMMddHHmm" var="pay" /> <f:formatDate
									value="${pay}" pattern="yyyy-MM-dd HH:mm" />
									<input name="tr_code"  value="${fb.appBillCode}"  type="hidden"/>
						</td>
						</tr>
                       <tr  id='tr${fb.appBillCode}' style="display: none" >
                       <td colspan="13">
                       <table id='table1'  class="list" width="100%">
                       <thead>
                       <c:if test="${fb.appType==1}">
                        <tr >
                       <th rowspan="2">学校名称</th>
                       <th rowspan="2">结算日期</th>
						<th rowspan="2">总人数</th>
						<th colspan="4" style="text-align:center">有效用户数</th>
						<th colspan="2" style="text-align:center">客户经理结算</th>
						<th colspan="2" style="text-align:center">学校现金返还</th>
						<th colspan="2" style="text-align:center">学校话费返还</th>
						<th colspan="2" style="text-align:center">管理员费用</th>
						<th rowspan="2">备注</th>
                       </tr>
                       <tr>
                       	<th>本期</th>
                       	<th>上期</th>
                       	<th>新增</th>
                       	<th>开通率</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	</tr>
                       	</c:if>
                       	 <c:if test="${fb.appType==2}">
                        <tr >
                       <th rowspan="2">地区名称</th>
                       <th rowspan="2">结算日期</th>
                       <th rowspan="2">学校数量</th>
						<th rowspan="2">总人数</th>
						<th colspan="4" style="text-align:center">有效用户数</th>
						<th colspan="2" style="text-align:center">行业经理结算</th>
						<th rowspan="2">备注</th>
                       </tr>
                       <tr>
                       	<th>本期</th>
                       	<th>上期</th>
                       	<th>新增</th>
                       	<th>开通率</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	</tr>
                       	</c:if>
                       </thead>
				      <tbody id="foreign${fb.appBillCode}">
				      </tbody>
                       </table>
                       </td>
                       </tr>
					</c:forEach>
				</tbody>

			</table>
		</div>
        <%@ include file="/WEB-INF/jsp/public/panelBar.jsp"%>